package com.hmsg.health.utils.umeng;

import java.util.HashMap;
import java.util.Map;

public class PushHandler {
	private static PushClient client = new PushClient();
	// setBadge 推送角标数
	public static Map<String, Integer> badgeMap;
	static {
		badgeMap = new HashMap<String, Integer>();
	}

	public static Map<String, Integer> getbadgeMap() {
		return badgeMap;
	}

	public static void setbadgeMap(Map<String, Integer> badgeMap) {
		PushHandler.badgeMap = badgeMap;
	}

	/**
	 * 
	 * @param userId
	 * @return
	 */
    public static int getBadge(String userId)
    {
        //条数统计
        String badgeKey = userId;
        
        if(badgeMap.get(badgeKey) == null){
        	badgeMap.put(badgeKey, 0);
        }
        int badge = badgeMap.get(badgeKey);
        return badge;
    }
    
   /**
    * 
    * @param userId
    * @param badge
    * @return
    */
    public static int setBadge(String userId,int badge)
    {
        //条数统计
        String BadgeKey = userId;
        badge++;
        badgeMap.put(BadgeKey, badge);
        return badge;
    }
	/**
	 * 自定义播(customizedcast)：开发者通过自有的alias进行推送，可以针对单个或者一批alias进行推送，也可以将alias存放到文件进行发送。
	 * 
	 * @param alias
	 * @param description
	 * @throws Exception
	 */
	public static void sendIOSCustomizedcast(String alias, String description,String page) throws Exception {
		IOSCustomizedcast customizedcast = new IOSCustomizedcast("5db659b64ca357b78f000d6e",
				"zqbdxwkc64pylbdf90enjwvcvbaaieip");
		
		customizedcast.setAlias(alias, "push");
		customizedcast.setAlert(description);
		customizedcast.setPage(page);
		// customizedcast.setBody(description);
		
		//发送，角标+1
		customizedcast.setBadge(getBadge(alias)+1);
		customizedcast.setSound("default");

		// TODO set 'production_mode' to 'true' if your app is under production
		customizedcast.setTestMode();
		System.out.println("==iosSend:" + customizedcast.getPostBody());
		client.send(customizedcast);
		
		//设置脚标+1；
		setBadge(alias,getBadge(alias));
	}

	public static void main(String[] args) throws Exception {
		 sendIOSCustomizedcast("e30cdc10f0fa4c98931e566a65a8683b","你收到我的推送了吗？记得多喝热水。","");
	}
}
